#  +----------------------------------------------------------------------+
#  | Makefile                                                             |
#  +----------------------------------------------------------------------+
include ../Makefile.clib

BIN_PATH  = .

HOM_CLUB = $(CLUBCOMM_HOME)
HOM_CCOMM=$(CLUBCOMM_HOME)
HOM_SVRBH=$(HOM_CCOMM)/spp/spp1.1.1-rc2/serverbench++

INC_QZHTTP=$(HOM_CCOMM)/qzhttp2.30.0/comm

LIBC_VER  = $(shell ls /lib/libc-*.so | cut -c11-13)

LIBC_CMP=2.4

ifneq ($(LIBC_VER),$(LIBC_CMP))
CFLAGS += -DSLK_LINUX
BIN=slk8
else
CFLAGS += -DSUS_LINUX
BIN=sus32
endif

BIN_CFLAGS= -g -Wall -fPIC 

CFLAGS += -g  -Wall -fPIC -shared
LFLAG += -g -Wall -D_GNU_SOURCE -fPIC
AR = ar
CR = cr

INC += -I$(CLIB_HOME)/include/httpframe -I$(HOM_SVRBH)/development -I$(HOM_CCOMM)/clib/include $(INC_L5) -I$(INC_QZHTTP)
LIB += $(LNK_L5)

FTAR=$(CLIB_HOME)/lib/libhttpframe.a
ETAR=$(CLIB_HOME)/lib/libhttpecho.so
ECGI=./echo.cgi
EBIN=./echo_test
CTAR=./HttpEchoClient

all : $(FTAR) $(ETAR) $(CTAR) $(ECGI) $(EBIN)

FOBJ= CgiEnvironment.o Engine.o HttpProtocolParse.o Log.o HttpWorker.o HttpCgi.o

EOBJ=EchoHandler.o HttpEchoEngine.o HttpEchoSvr.o 
ELIB=-L$(CLIB_HOME)/lib -lhttpframe

ECGI_OBJ=EchoHandler.o HttpEchoEngine.o EchoCgi.o
ECGI_LIB=-L$(CLIB_HOME)/lib -lhttpframe

EBIN_OBJ=EchoHandler.o HttpEchoEngine.o EchoCgi.o
EBIN_LIB=-L$(CLIB_HOME)/lib -lhttpframe

COBJ=HttpEchoClient.o HttpProtocolParse.o 
CLIB=-L$(HOM_CCOMM)/clib/lib -lclib_sock $(LNK_L5)
CINC=-I$(HOM_CCOMM)/clib/include


$(FTAR):$(FOBJ)
	echo build $(FTAR)
	$(AR) $(CR) $(FTAR) $(FOBJ)
	
$(ETAR):$(EOBJ)
	echo -e Linking $(ETAR)
	$(CXX) -o $@ $^ $(CFLAGS) $(LIB) $(ELIB) 
	#cp -f $(HOM_SVRBH)/$(BIN)/bin/spp_ctrl ../bin/spp_ctrl_echo
	#cp -f $(HOM_SVRBH)/$(BIN)/bin/spp_proxy ../bin/spp_proxy_echo
	#cp -f $(HOM_SVRBH)/$(BIN)/bin/spp_worker ../bin/spp_worker_echo
	#chmod +x ../bin/*
	
$(ECGI):$(ECGI_OBJ)
	echo -e Linking $(ECGI)
	$(CXX) -o $@ $^ $(CFLAGS) -z defs $(LIB) $(ECGI_LIB) 

$(EBIN):$(EBIN_OBJ)
	echo -e Linking $(EBIN)
	$(CXX) -o $@ $^ $(BIN_CFLAGS)  $(LIB) $(EBIN_LIB) 
	
$(CTAR):$(COBJ)
	echo -e Linking $(CTAR)
	$(CXX) -o $@ $^ $(LFLAGS) $(LIB) $(CLIB) 

	
%.o: %.cpp
	echo -e Compling 
	$(CXX) $(CFLAGS) -c -o $@ $< $(INC) 
%.o: %.c
	echo -e Compling 
	$(CC) $(CFLAGS) -c -o $@ $< $(INC) 


clean: 
	rm -f *.o
	rm -f *.a
	rm -f *.so
	rm -f $(ETAR)
	@#rm -rf $(TAR)


